﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Web.Filter;
using Web.Models;
using System.Xml;
using fqlmoney.Common;
using fqlmoney.Model;
using fqlmoney.BLL;

namespace fqlmoney.Controllers
{
    
    public class TypeController : Controller
    {
        MoneyTypeBLL bll = new MoneyTypeBLL();
       
        /// <summary>
        /// 分类list
        /// </summary>
        /// <returns></returns>
        [CheckAdminLogin]
        public ActionResult List(int page = 1)
        {
            userinfo model_userinfo = BaseOperater.getAdmin(HttpContext);
            string extsql = " and u_id="+ model_userinfo.u_id;
            int totalPages = 0;
            int totalItems = 0;
            int pageCount = 10;
           
            ViewBag.list = bll.GetPage(extsql, page, pageCount, ref totalPages, ref totalItems);

            ViewBag.userinfo = model_userinfo;
            ViewBag.request_url = Request.Path.ToString();
            ViewBag.page = page;
            ViewBag.pagesize = pageCount;
            ViewBag.search_url = "";
            ViewBag.totalpage = totalPages;
            ViewBag.totalcount = totalItems;
            return View();
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [CheckAdminLoginAjax]
        public JsonResult Add()
        {
            userinfo model_userinfo = BaseOperater.getAdmin(HttpContext);
            user_moneytype model = new user_moneytype();
            model.t_name = Request.Form["t_name"];
            model.t_state =Utils.StrToInt(Request.Form["t_state"],2);
            model.u_id = model_userinfo.u_id;
            return Json(bll.Add(model));
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [CheckAdminLoginAjax]
        public JsonResult Update()
        {
            user_moneytype model = new user_moneytype();
            model.t_name = Request.Form["t_name"];
            model.t_state = Utils.StrToInt(Request.Form["t_state"], 2);
            model.t_id = Utils.StrToInt(Request.Form["t_id"],0);
            return Json(bll.Update(model));
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [CheckAdminLoginAjax]
        public JsonResult Delete()
        {
            userinfo model_userinfo = BaseOperater.getAdmin(HttpContext);
            return Json(bll.Delete(Utils.StrToInt(Request.Form["id"],0),model_userinfo.u_id));
        }

    }
}